package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author Fxz
 * @version 1.0
 * @date 2022-02-05 17:16
 */
@RestController
@SuppressWarnings("all")
@RequiredArgsConstructor
@RequestMapping("/admin/product")
public class SpuManageController {

	private final ManageService manageService;

	/**
	 * 跟据三级分类id分页查询spu
	 */
	@GetMapping("{page}/{limit}")
	public Result<IPage<SpuInfo>> getSpuInfoList(@PathVariable("page") Long page, @PathVariable("limit") Long limit,
			SpuInfo spuInfo) {
		return Result.ok(manageService.getSpuInfoList(new Page<>(page, limit), spuInfo));
	}

	/**
	 * 获取所有销售属性
	 */
	@GetMapping("/baseSaleAttrList")
	public Result baseSaleAttrList() {
		return Result.ok(manageService.getBaseSaleAttrList());
	}

	/**
	 * 保存spu信息
	 */
	@PostMapping("/saveSpuInfo")
	public Result saveSpuInfo(@RequestBody SpuInfo spuInfo) {
		return Result.ok(manageService.saveSpuInfo(spuInfo));
	}

	/**
	 * 跟据spuId查询spuImage列表
	 */
	@GetMapping("/spuImageList/{spuId}")
	public Result getSpuImageList(@PathVariable("spuId") Long spuId) {
		return Result.ok(manageService.getSpuImageList(spuId));
	}

	/**
	 * 跟据spuId查询spu对应的销售属性以及销售属性值
	 */
	@GetMapping("/spuSaleAttrList/{spuId}")
	public Result getSpuSaleAttrList(@PathVariable("spuId") Long spuId) {
		return Result.ok(manageService.getSpuSaleAttrList(spuId));
	}

}
